/*
 * @Author: hyq
 * @LastEditors: hyq
 * @Description: throttle
 * @Date: 2023-12-05 10:56:07
 */
export default function throttle(fn: any, delay: number, immediate = true) {
  let timer: number | undefined
  return function (this: any, ...args: any[]) {
    console.log(immediate)
    if (immediate) {
      fn.apply(this, args)
      immediate = false
      return
    }
    clearTimeout(timer)
    timer = setTimeout(() => {
      fn.apply(this, args)
    }, delay)
  }
}
